public class HashBuck2<K,V> {
    private static class Node<K,V>{
        private K Key;
        private V val;
        private Node next;

        private Node(K key, V val) {
            Key = key;
            this.val = val;
        }
    }

    private Node<K,V>[] arr;
    private int sz;
    private static final double DEFAULT = 0.75;

    public HashBuck2() {
        this.arr = (Node<K,V>[])new Node[10];
    }
    public void put(K key,V val){
        int hash = key.hashCode();
        int index = hash% arr.length;
        if(arr[index]==null) {
            arr[index] = new Node<K,V>(key,val);
        }
        else{
            Node<K,V> cut = arr[index];
            while(cut.next!=null){
                if(cut.Key.equals(key)){
                    cut.val=val;
                    return;
                }
                cut=cut.next;
            }
            cut.next= new Node<K,V>(key,val);
        }
        sz++;
        //fz();
    }
    /*private void fz(){
        double a = sz*1.0/arr.length;
        if(a>=DEFAULT){
            //arr= Arrays.copyOf(arr,arr.length*2);
            Node[] newArr = new Node[2* arr.length];
            for (int i = 0; i < arr.length; i++) {
                Node cut1 = arr[i];
                while(cut1!=null){
                    int index = cut1.val% newArr.length;
                    if(newArr[index]==null) {
                        newArr[index] = new HashBuck.Node(cut1.key, cut1.val);
                    }
                    else{
                        HashBuck.Node cut = arr[index];
                        while(cut.next!=null){
                            if(cut.key==cut1.key){
                                cut.val=cut1.val;
                            }
                            cut=cut.next;
                        }
                        cut.next= new HashBuck.Node(cut1.key, cut1.val);
                    }
                    cut1=cut1.next;
                }
            }
            arr=newArr;
        }
    }*/

    public V getval(K key){
        int hash = key.hashCode();
        int i = hash%arr.length;
        Node<K,V> node = arr[i];
        while (node!=null){
            if(node.Key.equals(key))
                return node.val;
            else
                node=node.next;
        }
        return null;
    }
}
